package xio.ccf_201503;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;

/**
 * 201503-4	网络延时 70分 超时 待优化
 */
public class NetDelay {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Graph g = new Graph(n+m+1);
		for (int i = 2; i <= n+m; i++) {
			g.addEdge(i, sc.nextInt());
		}
		
		
		for (int i = 1; i < g.N; i++) {
			marked = new boolean[g.N];
			dfs(g, i);		
			edgeCount = 0;
		}
		
		System.out.println(result);
		
	}
	static int edgeCount;
	static boolean marked[];
	static int  result;
	
	static void dfs(Graph g,int v) {
		
		marked[v] = true;
		for (int u : g.adj(v)) {
			if (!marked[u]) {
				edgeCount++;
				dfs(g, u);
				if (edgeCount > result) {
					result = edgeCount;
				}
				edgeCount--;
			}
		}
		
	}
	
	static class Graph {
        List<LinkedHashSet<Integer>> adj;
        int N;
        
        public Graph(int N) {
        	this.N = N;
            adj = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                LinkedHashSet<Integer> s = new LinkedHashSet<>();
                adj.add(s);
            }
        }

        public void addEdge(int a, int b) {
            adj.get(a).add(b);
            adj.get(b).add(a);
        }

        public Iterable<Integer> adj(int v) {
            return adj.get(v);
        }
    }
}
